<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title><?php echo $store_name;?></title>
        <meta charset="UTF-8">
        <meta name="description" content="<?php echo $action['action_name'];?>">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body <?php  if(strstr($_SERVER['REQUEST_URI'],'user/passport/') ){ echo 'class="_login_backimg"';} ?> >
 
<link href="/public/css/main.css" rel="stylesheet">
<div class="container" style='font-size:10px;' >
    <div class='_main_'>
        <div style='height:1.5rem'></div>
        <div class="<?php if(strstr($_SERVER['REQUEST_URI'],'user/passport/')){ echo '_banner';}else{ echo 'banner';}?>">
            <?php if(!strstr($_SERVER['REQUEST_URI'],'user/passport/')){?>
            <div class='_logo' style='height: 25rem'>
                <a href='#'><img src="/public/images/kaka.png" class='logo_img'  alt='banner' style="width:30%"/></a>
            </div>
            <?php } ?>
            <img src="<?php echo strlen($logo)<1?'/public/images/KAKA-LOGO.png':$logo;?>" class="<?php if(strstr($_SERVER['REQUEST_URI'],'user/passport/')){ echo '_banner_img'; }else{ echo 'banner_img'; }?>"  id='change'  alt='banner' />
            <?php if($barber['id']>0){?>
            <div style='text-align:center;width:13rem;height: 13rem;right:2%;margin-top:-9rem;position: absolute;z-index:100;background-color:white;border-radius:50%;'>
                <div style='height:12rem;width:12rem;margin:0.5rem auto'>
                <img src="<?php if(strlen($barber['photo'])>0){echo $barber['photo'];}else{echo '/public/images/tou.png';}?>" id='change'  style="width:100%;height: 100%;border-radius:50%;overflow:hidden;">
                </div>
                <div style='height:1rem'></div>
                <font style="font-size:1.5rem;color:black"><b><?php echo $barber['level'].' : '.$barber['name'];?></b></font>
            </div>
            <?php }?>
        </div>
 

<div class="container">
    <div class='_main_'>
<link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="/public/css/main.css" rel="stylesheet">
<script type='text/javascript' src='/public/js/jquery-1.11.2.min.js'></script>
<script type="text/javascript" src='/public/js/jquery.validate.js'></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div style='height:1.5rem'></div>
<div class='_cut2' ></div>
<form id='form' >
    <?php if(!is_array($data)){ echo "<div style='text-align:center;' >".$data."</div>";exit;} foreach($data as $k=>$v){ if($v['id']=='') { continue; } for($i=0;$i<count($v['_items']);$i++){ if($v['_items'][$i]['type'] == $type && $v['order_number']==$order_number || !isset($v['_items'][$i]['type']) ){ continue; } ?>
    <div class='row'>
      <?php if($v['order_number']!=$order_number ){ ?>
        <input type='hidden' value='<?php echo $v['store_id']; ?>' name='store_id' >
        <input type='hidden' value='<?php echo $v['id']; ?>' name='order_id' >
        <input type='hidden' value='<?php echo $v['order_number']; ?>' name='order_number' >
        <input type='hidden' value='<?php echo $v['price']; ?>' name='price' >
        <span style='float:left;padding:1rem;'><input id='check<?php echo $k;?>' name="check" onclick="ch(<?php echo $k;?>)"  type="checkbox" value="" /></span>
        <?php }else{ ?>
        <span style='float:left;padding:2rem;'></span>
        <?php  } ?>
        <div class='thumbnail' style="float:left;">
            <div style="height:8rem;width:8rem;overflow: hidden;">
               <a href="<?php if($v['team_number']){ echo shop_buildUrl('/user/action/info?aid='.$v['action_id'].'&team_number='.$v['team_number']); }else{ echo shop_buildUrl('/user/shop/info?item_id='.$v['_items'][$i]['item_id']); } ?>" >
                <img class='_img' src="<?php  echo 'http://'.IMAGE_DOMAIN_.$v['_items'][$i]['item']['images'][0]['image'] ;?>" style='width:100%;height:100%'/></a>
            </div>
        </div>
        <div id='names'>
            <div  style='font-size:1.2rem;margin-top:1rem;' ><?php echo $v['_items'][$i]['item']['name'];?></div>
            <div class='_line'></div>
            <div ><i><font style='color:red;font-size:1.7rem'>￥<?php if($v['action_id']==0){ echo $v['_items'][$i]['item']['price']/100;}else{ echo $v['_items']['orders']['action_price']['ids'][$v['_items'][$i]['item']['id']]/100; }?></font></i>
                
            <span  style='float:right' >数量：<i><font style='color:red;font-size:1.7rem;float:right'><?php if($v['_items'][$i]['item']['items'][0]['number']){ echo ($v['_items'][$i]['count']/$v['_items'][$i]['item']['items'][0]['number']); }else{ echo ($v['_items'][$i]['count']); } ?></font></i></span>
            
            </div>
            <div style='float:right;overflow:hidden;color:red'>
               待付款
            </div>
        </div>
        <div class='_line' style='height:1rem;' ></div>

    </div>
    <?php $order_number = $v['order_number']; $type=$v['_items'][$i]['type']; } }?>
</form>

<div class='box navbar-fixed-bottom' style="background-color:#EEEEEE;">
    <button class="btn btn-primary btn-lg"  type="button" id='pay' style="width:30%;background-color:#FF79BC;border-color:white;float:right;">去结算(<span id='num' >0</span>)</button>
    <span style='padding:1rem;float:right;'>共计：<span style='text-align:right'>￥<span id='money' style='color:red;font-size:1.7rem;'>0</span><br> (不含优惠劵)</span></span>&nbsp;&nbsp;&nbsp;
</div>

<div class='_line'></div>
<div class='_line'></div>
        <input type="hidden" value="<?php echo $status;?>" id="page_status" >


</body></html>
<script type="text/javascript">
    $(document).ready(function(){

        var number = 12;
        var page_status = $('#page_status').val();
        var page_stores = eval('('+ $("#page_stores").val() +')');
        var last_type = '';
        var last_order_number = "";

        $('#pay').click(function(){
            if(! $(":checkbox[name='check']").is(':checked')) {
                alert('请先选择商品！');
                return;
            }
            var str = 0;
            var price = 0;
            var order_number = '';
            var order_id =0;
            var store_id = 0;
            $(":checkbox[name='check']").each(function () {
                if ($(this).is(":checked")) {
                   price = $(this).parent().prev().val();
                   order_number = $(this).parent().prev().prev().val();
                   order_id = $(this).parent().prev().prev().prev().val();
                   store_id = $(this).parent().prev().prev().prev().prev().val();
                   str +=1;
                }
                
            });
            if( str>1) {
                alert('请选择一个订单！');
                return;
            }
            window.location.href = "<?php echo shop_buildUrl('/user/shop/pay?order_id="+order_id+"&price="+store_id+"&order_number="+order_number+"&price="+price+"'); ?>";

         });

        ////////////////////////////////////////////////////////
        $(window).scroll(function () {
            loaddata();
        });
        function loaddata() {
            if (number == -1) {
                return;
            }
            totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
            if ($(document).height() <= totalheight) {
                store_id = $('#store_id').val();
                $.ajax({
                    url: "<?php echo shop_buildUrl('/user/shop/append?status="+ page_status +"&start=" + number + "') ?>",
                    async: true,
                    success: function (msg) {
                        if ( msg == 'false') {
                            number = -1;
                            return;
                        }
                        var html = "";
                        msg = eval('(' + msg + ')');
                        // console.log( msg );
                        $.each( msg, function ( k, v ) {

                            if ( v.id == "" ){
                                return;
                            }
                            for ( var i = 0; i < v._items.length; i++ ){
                                if ( v._items[i].type == last_type && v.order_number == last_order_number || v._items[i].type == "undefined" ){
                                    return;
                                }
                                html += '<div class="row">';
                                if ( v.order_number != last_order_number ){
                                    html += '<input type="hidden" value="'+ v.store_id +'" name="store_id">';
                                    html += '<input type="hidden" value="'+ v.id +'" name="order_id">';
                                    html += '<input type="hidden" value="'+ v.order_number +'" name="order_number">';
                                    html += '<input type="hidden" value="'+ v.price +'" name="price">';
                                    html += '<span style="float: left;padding: 1rem;">';
                                    html += '<input id="check'+v.order_number+'" name="check" onclick="ch('+v.order_number+')" type="checkbox" value="" />';
                                    html += '</span>';
                                }else{
                                    html += '<span style="float: left;padding: 2rem"></span>';
                                }
                                html += '<div class="thumbnail" style="float:left;">';
                                html += '<div style="height:8rem;width:8rem;overflow: hidden;">';
                                if ( v.team_number ) { 
                                    f_url = '<?php echo shop_buildUrl("/user/action/info?aid='+v.action_id+'&team_number='+v.team_number+'"); ?>'; 
                                }else{ 
                                    f_url = '<?php echo shop_buildUrl("/user/shop/info?item_id='+v._items[i].item_id+'"); ?>'; 
                                } 
                                html += '<a href="'+ f_url +'">';
                                html += '<img class="_img" src="http://'+ '<?php echo IMAGE_DOMAIN_; ?>'+ v._items[i].item.images[0].image+'" style="width: 100%; height: 100%;">';
                                html += '</a>';
                                html += '</div>';
                                html += '</div>';
                                html += '<div id="names">';
                                html += '<div style="font-size: 1.2rem;margin-top: 1rem">' + v._items[i].item.name + '</div>';
                                html += '<div class="_line"></div>';
                                html += '<div><i><font style="color: red;font-size:1.7rem">￥';
                                if ( v.action_id == 0 ){
                                    html += v._items[i].item.price/100;
                                }else{
                                    html += v._items.orders.action_price.ids[ v._items[i].item.id ] /100;
                                }
                                html += '</font></i>';
                                html += '<span style="float: right">数量：<i><font style="color: red;font-size: 1.7rem;float: right">';
                                if ( v._items[i].item.items ){
                                    html += ( ( v._items[i].count ) / ( v._items[i].item.items[0].number ) );
                                }else{
                                    html += v._items[i].count;
                                }
                                html += '</font></i></span></div>';
                                html += '<div style="float: right;overflow: hidden;color: red">待付款</div></div><div class="_line" style="height: 1rem;"></div></div>';

                                last_type = v._items[i].type;
                                last_order_number = v.order_number;
                            }
                            number += 1;
                        });
                        // console.log( html );
                        $('#form').append( html );
                    }
                });
            }
        }
        ////////////////////////////////////////////////////////

    })
    function ch(type){
        if($('#check'+type).is(':checked')){
            var price = $($('#check'+type)).parent().prev().val();
        }
        var num = 1;
        $('#num').html(num);
        $('#money').html(price/100);
    }

</script>